<template>
  <component :is="RTcomponentId" :currentResume="props.currentResume" @surrender="surrender" @disConnect="disConnect"
    @changeDate="changeDate" :process="process" :trainStatus="trainStatus" @dieOut="dieOut"></component>
  <SurrenderModal ref="surrenderModal" @closeModal="closeModal" :process="process"></SurrenderModal>
  <DisConnectModal :process="process" ref="disconnectModalRef" @closeModal="closeModal"></DisConnectModal>
  <ChangeDateModal :process="process" ref="changeDateModalRef" @closeModal="closeModal"></ChangeDateModal>
  <DieOutModal :process="process" ref="dieOutModalRef" @closeModal="closeModal"></DieOutModal>
</template>

<script setup lang='ts'>
import { ref, watch } from "vue"
import SurrenderModal from "../Modals/SurrenderModal.vue";  // 放弃模态框
import DisConnectModal from "../Modals/DisConnectModal.vue"; //未联系上模态框
import ChangeDateModal from "../Modals/ChangeDateModal.vue";  //改期模态框
import DieOutModal from "../Modals/DieOutModal.vue";  //淘汰的模态框
import CVWatting from "./CVTache/CVWatting.vue"; //简历环节-待筛选
import CVDieOut from "./CVTache/CVDieOut.vue";//简历环节-淘汰
import TobeInterviewed from "./InterviewTache/Tobe/TobeInterviewed.vue"; //待约面
import TobeSurrender from "./InterviewTache/Tobe/TobeSurrender.vue";//待约面-放弃
import WattingArrange from "./InterviewTache/Watting/WattingArrange.vue";//待面试
import WattingSurrender from "./InterviewTache/Watting/WattingSurrender.vue";//待面试-放弃
import ArrivalInterview from "./InterviewTache/Arrival/ArrivalInterview.vue"; //到面
import ArrivalSurrender from "./InterviewTache/Arrival/ArrivalSurrender.vue"; //到面-放弃
import ArrivalDieOut from "./InterviewTache/Arrival/ArrivalDieOut.vue"; //到面-淘汰
import Train from "./InterviewTache/Train/Train.vue"; //培训环节
import Contract from "./InterviewTache/Contract/Contract.vue"; //签约环节
import Entry from "./InterviewTache/Entry/Entry.vue";
import OtherStatus from "./InterviewTache/Other/OtherStatus.vue";
import { comStores } from '@/store/common/comStore';
const store = comStores();
const props = defineProps(['currentResume'])

const RTComponentList = [
  { key: "2", component: CVWatting },
  { key: "4", component: CVDieOut },
  { key: "5", component: TobeInterviewed },
  { key: "7", component: TobeSurrender },
  { key: "8", component: WattingArrange },
  { key: "10", component: WattingSurrender },
  { key: "11", component: ArrivalInterview },
  { key: "13", component: ArrivalDieOut },
  { key: "14", component: ArrivalSurrender },
  { key: "15", component: Train, label: "待约培训" },
  { key: "16", component: Train, label: "待约培训" },
  { key: "17", component: Train, label: "待约培训-放弃" },
  { key: "18", component: Train, label: "待培训" },
  { key: "20", component: Train, label: "预约邮件已发送" },
  { key: "22", component: Train, label: "预约邮件已发送-放弃" },
  { key: "23", component: Train, label: "培训中" },
  { key: "27", component: Train, label: "培训中-放弃" },
  { key: "25", component: Train, label: "培训中-淘汰" },
  { key: "28", component: Train, label: "考核" },
  { key: "29", component: Train, label: "考核评价" },
  { key: "30", component: Train, label: "待录取" },
  { key: "32", component: Train, label: "待录取-淘汰" },
  { key: "33", component: Contract, label: "待签应约" },
  { key: "35", component: Contract, label: "待签应约-放弃" },
  { key: "36", component: Contract, label: "待签三方" },
  { key: "38", component: Contract, label: "待签三方-放弃" },
  { key: "39", component: Contract, label: "二次面试" },
  { key: "40", component: Contract, label: "二次面试-通过" },
  { key: "41", component: Contract, label: "二次面试-淘汰" },
  { key: "42", component: Contract, label: "二次面试-放弃" },
  { key: "43", component: Entry, label: "待入职" },
  { key: "44", component: Entry, label: "待入职" },
  { key: "45", component: Entry, label: "待入职-放弃" },
  { key: "46", component: Entry, label: "实习中" },
  { key: "49", component: Entry, label: "实习中-放弃" },
  { key: "48", component: Entry, label: "实习中-淘汰" },
  { key: "50", component: Entry, label: "试用中" },
  { key: "53", component: Entry, label: "试用中-放弃" },
  { key: "52", component: Entry, label: "试用中-淘汰" },
  { key: "54", component: Entry, label: "已转正" },
  { key: "-1", component: OtherStatus }
]
const RTcomponentId = ref<any>();
const trainStatus = ref<string>("");
const process = ref<any>({})
watch(() => store.currentProcess, (val) => {
  console.log(val, '===>val')
  if(!val.key) return
  let current: any = RTComponentList.find(el => el.key == val.key);
  console.log(current, 'current')
  if (current) {
    process.value = { ...current, ...store.currentResume }
    RTcomponentId.value = current.component;
    if (current?.label) {
      trainStatus.value = current.label
    }
  } else {
    process.value = store.currentResume;
    RTcomponentId.value = OtherStatus;
  }
}, { deep: true, immediate: true })
const surrender = (val: string) => {
  console.log('surrender====>', process.value)
  console.log('surrender====>', val)
  // process.value = val
  surrenderModal.value.show = true
}
const surrenderModal = ref<any>(null)
const disconnectModalRef = ref<any>(null);
const changeDateModalRef = ref<any>(null);
const dieOutModalRef = ref<any>(null)
const closeModal = () => {
  console.log('closeModal')
  surrenderModal.value.show = false
  disconnectModalRef.value.show = false;
  changeDateModalRef.value.show = false
}
const disConnect = () => {  //未联系上
  disconnectModalRef.value.show = true
}
const changeDate = (val) => {
  console.log(val, '===>val')
  changeDateModalRef.value.show = true
}
const dieOut = () => {
  dieOutModalRef.value.show = true
}
</script>

<style></style>